package com.qupai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qupai.domain.dto.AuctionItemDTO;
import com.qupai.domain.entity.AuctionItem;
import com.qupai.mapper.AuctionItemMapper;
import com.qupai.service.IAuctionItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 拍卖商品表，存储拍卖商品信息 服务实现类
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-07-30
 */
@Service
@RequiredArgsConstructor
public class AuctionItemServiceImpl extends ServiceImpl<AuctionItemMapper, AuctionItem> implements IAuctionItemService {


    private final AuctionItemMapper auctionItemMapper;

    @Override
    public void add(AuctionItemDTO auctionItemDTO) {
        AuctionItem auctionItem=new AuctionItem();
        BeanUtils.copyProperties(auctionItemDTO,auctionItem);
        auctionItem.setCurrentHighestBid(auctionItemDTO.getStartingPrice());//当前最高价就是起拍价
        auctionItem.setAuctionStatus(1); //待拍卖

        auctionItemMapper.insert(auctionItem);

    }

    @Override
    public void updateItem(AuctionItemDTO auctionItemDTO) {
        AuctionItem auctionItem=new AuctionItem();
        BeanUtils.copyProperties(auctionItemDTO,auctionItem);
        auctionItemMapper.updateById(auctionItem);
    }

    @Override
    public List<AuctionItem> getItemByAuctionId(Long auctionId) {
        QueryWrapper<AuctionItem>wrapper=new QueryWrapper<>();
        wrapper.lambda().eq(AuctionItem::getAuctionId,auctionId);
        return auctionItemMapper.selectList(wrapper);

    }
}
